package com.hzya.frame.utils.help;
import java.util.regex.Matcher;
import org.apache.oro.text.GlobCompiler;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.PatternMatcher;
import org.apache.oro.text.regex.Perl5Matcher;

public final class RegexpHelper
{
  private static String separator = ",";

  public static void main(String[] args)
  {
    System.out.println(isGlobmatches("sdfdf.jar", "*.jar"));
    System.out.println(isGlobmatches("sdfdfjar", "*.jar"));
  }

  public static final boolean isGlobmatches(String str, String patternstr) {
    if (patternstr != null && !"".equals(patternstr)) {
      GlobCompiler compiler = new GlobCompiler();
      PatternMatcher matcher = new Perl5Matcher();
      if (patternstr.indexOf(separator) == -1) {
        try {
          Pattern pattern = compiler.compile(patternstr);
          return matcher.matches(str, pattern);
        } catch (MalformedPatternException var8) {
          throw new RuntimeException(var8);
        }
      } else {
        String[] patterns = patternstr.split(separator);

        for(int i = 0; i < patterns.length; ++i) {
          try {
            Pattern pattern = compiler.compile(patterns[i]);
            boolean result = matcher.matches(str, pattern);
            if (result) {
              return result;
            }
          } catch (MalformedPatternException var9) {
            throw new RuntimeException(var9);
          }
        }

        return false;
      }
    } else {
      return false;
    }
  }

  public static boolean regexEqual(String aim_str, String match_str)
  {
    java.util.regex.Pattern p = java.util.regex.Pattern.compile(match_str);
    Matcher m = p.matcher(aim_str);
    return m.find();
  }

  public static boolean azAz09_4_20(String arg0)
  {
    if (arg0 == null) {
      return false;
    }

    return (regexEqual(arg0, "^[a-zA-Z0-9]{4,20}$"));
  }

  public static boolean reg09(String arg0)
  {
    if (arg0 == null) {
      return false;
    }

    return (regexEqual(arg0, "^[0-9]{1,}$"));
  }

  public static boolean isEmail(String email)
  {
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("^\\w+([-.]\\w+)*@\\w+([-]\\w+)*\\.(\\w+([-]\\w+)*\\.)*[a-z]{2,3}$");
    Matcher matcher = pattern.matcher(email);

    return (matcher.matches());
  }

  public static boolean isPhone(String phone)
  {
    return reg09(phone);
  }

  public static boolean isNumeric(String str)
  {
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("[0-9]*");
    Matcher isNum = pattern.matcher(str);

    return (isNum.matches());
  }

  public static boolean isWord(String str)
  {
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("[a-zA-Z]+");
    Matcher is_word = pattern.matcher(str);

    return (is_word.matches());
  }
}